package com.example.mapkittest.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.mapkittest.models.Landmark
import com.example.mapkittest.repositories.Attractions
import com.yandex.mapkit.geometry.Point
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

class LandmarkViewModel : ViewModel() {
    private val _landmarks: MutableStateFlow<List<Landmark>> = MutableStateFlow(listOf())
    val landmark: Flow<List<Landmark>> = _landmarks.asStateFlow()
    private val _userLocation: MutableStateFlow<Point> = MutableStateFlow(Point())
    val userLocation: Flow<Point> = _userLocation.asStateFlow()
    var zoom: Float = 0f
    var tilt: Float = 0f
    var azimuth: Float = 0f
    var position: Point = Point()

    init {
        loadLandmarks()
    }

    fun updateUserLocation(point: Point) {
        viewModelScope.launch {
            _userLocation.value = point
        }
    }

    private fun loadLandmarks() {
        viewModelScope.launch {
            _landmarks.value = Attractions().landmarks
        }
    }
}